const router = require('express').Router();
const multer  = require('multer');

const path = require('path');


const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, './public/uploads')
  },
  filename: function (req, file, cb) {
  
    cb(null, file.fieldname + '-' + Date.now()+path.extname(file.originalname))
  }
})
 
var upload = multer({ storage: storage })


router.get('/upload', (req, res) => {
  res.render('upload')
})

router.post('/upload', upload.single('img'), (req, res) => {
  res.send('上传成功')
})

module.exports = router;